
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import net.sf.asterisk.manager.AuthenticationFailedException;
import net.sf.asterisk.manager.TimeoutException;

public class Teste implements managerSIP.ManagerListener{

	/**
	 * @uml.property  name="myManagerSIP"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	managerSIP.Manager myManagerSIP;

	public Teste(String hostname, String username, String password) {
		myManagerSIP = new managerSIP.Manager(this,hostname,username,password);
		try {
		    test();
		} catch (IllegalArgumentException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		} catch (IllegalStateException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		} catch (IOException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		} catch (SQLException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		} catch (AuthenticationFailedException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		} catch (TimeoutException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		} catch (InterruptedException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		if (args.length < 3) {
			printUsage();
		}
		else {
			try {
				//Reading the arguments passaded through the command line
				String hostname = args[0];
				String username = args[1];
				String password = args[2];
				new Teste(hostname, username, password);
			}
			catch (Exception e) {
				e.printStackTrace();

			}
		}
	}

	static void printUsage() {
		System.out.println("Expected arguments: hostname username password");
	}

	void test() throws IllegalArgumentException, IllegalStateException, IOException, SQLException, AuthenticationFailedException, TimeoutException, InterruptedException{
		//Call some methods from Manager just to test;

		//Diferent Sessions
		/*
		List<String> usersSession = new ArrayList<String>();
		usersSession.add("beta");
		usersSession.add("ze");
		myManagerSIP.createSession("SESSION1",usersSession);

		List<String> usersSession1 = new ArrayList<String>();
		usersSession1.add("jj");
		myManagerSIP.createSession("SESSION2",usersSession1);

		List<String> userToConfIds = new ArrayList<String>();
		userToConfIds.add("beta");
		myManagerSIP.createConference("SESSION1",userToConfIds);

		List<String> userToConfIds1 = new ArrayList<String>();
		userToConfIds1.add("jj");
		myManagerSIP.createConference("SESSION2",userToConfIds1);
		*/
		
		//Same Session

		List<String> usersSession = new ArrayList<String>();
		usersSession.add("beta");
		usersSession.add("jj");
		usersSession.add("ze");
		usersSession.add("joao");
		myManagerSIP.createSession("SESSION1",usersSession);
		
		List<String> userToConfIds = new ArrayList<String>();
		userToConfIds.add("beta");
		myManagerSIP.createConference("SESSION1",userToConfIds);

		List<String> userToConfIds1 = new ArrayList<String>();
		userToConfIds1.add("jj");
		myManagerSIP.createConference("SESSION1",userToConfIds1);
		
		List<String> userToConfIds2 = new ArrayList<String>();
		userToConfIds1.add("ze");
		myManagerSIP.createConference("SESSION1",userToConfIds2);
		
		List<String> userToConfIds3 = new ArrayList<String>();
		userToConfIds1.add("joao");
		myManagerSIP.createConference("SESSION1",userToConfIds3);
	
		/*
		myManagerSIP.delUserConference("SESSION1", "beta");
		myManagerSIP.addUserConference("SESSION1", "jj", "beta");
		myManagerSIP.delUserConference("SESSION1", "ze");
		myManagerSIP.addUserConference("SESSION1", "beta", "ze");
		myManagerSIP.delUserConference("SESSION1", "joao");
		myManagerSIP.addUserConference("SESSION1", "ze", "joao");
		*/
		myManagerSIP.delUserConference("SESSION1", "joao");
		myManagerSIP.delUserConference("SESSION1", "ze");
		
		List<String> userList4 = new ArrayList<String>();
		userList4.add("joao");
		userList4.add("ze");
		myManagerSIP.createConference("SESSION1", userList4);
		
		
		
	//	myManagerSIP.changeConference("beta", "SESSION1",numberSrc, numberDest);

	}

	/**
	 * userJoinedConference
	 *
	 * @param sessionName String
	 * @param conference int
	 * @param userID String
	 */
	public void userJoinedConference(String sessionName, int conference,
			String userID) {
		//Do nothing
		System.out.println(sessionName + "-- User " + userID + " joins the conference " + conference);
	}

	/**
	 * userLeaveConference
	 *
	 * @param sessionName String
	 * @param conference int
	 * @param userID String
	 */
	public void userLeaveConference(String sessionName, int conference, String userID) {
		//	Do nothing
		System.out.println(sessionName + "-- User " + userID + " leaves the conference " + conference);
	}

	/**
	 * userJoinedSession
	 *
	 * @param session String
	 * @param userID String
	 */
	public void userJoinedSession(String session, String userID) {
		//Do nothing
		System.out.println(session + "--" + userID);

	}
	public void userJoinedConference(String sessionName, int conference, String userID, String user) {
		// TODO Auto-generated method stub

	}
	public void userLeaveConference(String sessionName, int conference, String userID, String user) {
		// TODO Auto-generated method stub

	}
	public void userLeaveSession(String session, String userID) {
		// TODO Auto-generated method stub
		
	}

}
